home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 388_01 / ae / 91 / winner / ant.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-19  |  1.4 KB  |  29 lines

  1. #include <ctype.h>
  2. #include <curses.h>
  3. #define T isspace(*(t=Z(p)))&&
  4. #define V return
  5. #define _ while
  6. int d,i,j,m,n,p,q,x,y;char*c,b[BUF],*f,*g=b,*h,k[]="hjklHJKL[]tbixWRQ",*t;
  7. char*Z(a){if(a<0)V b;V b+a+(b+a<g?0:h-g);}P(a)char*a;{V
  8. a-b-(a<h?0:h-g);}S(){p=0;}bf(){n=p=P(c);}Q(){q=1;}C(){clear();Y();}
  9. G(){t=Z(p);_(t<g)*--h= *--g;_(h<t)*g++= *h++;p=P(h);}B(){_(!T b<t)--p;_(T
  10. b<t)--p;}M(a){_(b<(t=Z(--a))&&*t-'\n');V
  11. b<t?++a:0;}N(a){_((t=Z(a++))<c&&*t-'\n');V
  12. t<c?a:P(c);}A(a,j){i=0;_((t=Z(a))<c&&*t-'\n'&&i<j){i+= *t-'\t'?1:8-(i&7);++a;}V
  13. a;}L(){0<p&&--p;}R(){p<P(c)&&++p;}U(){p=A(M(M(p)-1),x);}
  14. D(){p=A(N(p),x);}H(){p=M(p);}E(){p=N(p);L();}
  15. J(){m=p=M(n-1);_(0<y--)D();n=P(c);}K(){j=d;_(0<--j)m=M(m-1),U();}
  16. I(){G();_((j=getch())-'\f'){if(j-'\b')g-h&&(*g++=j-'\r'?j:'\n');else
  17. b<g&&--g;p=P(h);Y();}}X(){G();p=h<c?P(++h):p;}
  18. F(){j=p;p=0;G();write(i=creat(f,MODE),h,(int)(c-h));close(i);p=j;}W(){_(!T
  19. t<c)++p;_(T
  20. t<c)++p;}int(*z[])()={L,D,U,R,B,J,K,W,H,E,S,bf,I,X,F,C,Q,G};
  21. Y(){m=p<m?M(p):m;if(n<=p){m=N(p);i=m-P(c)?d:d-2;_(0<i--)m=M(m-1);}
  22. move(0,0);i=j=0;n=m;_(1){p-n||(y=i,x=j);t=Z(n);if(d<=i||c<=t)break;
  23. if(*t-'\r')addch(*t),j+= *t-'\t'?1:8-(j&7);if(*t=='\n'||COLS<=j)
  24. ++i,j=0;++n;}clrtobot();++i<d&&mvaddstr(i,0,"<< EOF >>");move(y,x);
  25. refresh();}main(u,v)char**v;{h=c=b+BUF;if(u<2)V
  26. 2;initscr();d=LINES;raw();noecho();idlok(stdscr,1);if(0<(i=open(f= *++v,0))){
  27. g+=read(i,b,BUF);g=g<b?b:g;close(i);}S();_(!q){Y();i=0;j=getch();
  28. _(k[i]&&j-k[i])++i;(*z[i])();}endwin();V 0;}
  29.